package analysis;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.VideoCapture;

import utils.ImageDeted;

public class VideoCap implements IDetection {

	public VideoCapture camera;
	Mat frame;

	int semaforo = 0;

	public VideoCap(int n) {

		semaforo = n;

		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		camera = new VideoCapture(0);

		System.out.println("Msec: " + camera.get(0));
		System.out.println("Frames: " + camera.get(1));
		System.out.println("AVI RATIO: " + camera.get(2));
		System.out.println("Width: " + camera.get(3));
		System.out.println("Height: " + camera.get(4));
		System.out.println("FPS: " + camera.get(5));
		System.out.println("Fourcc: " + camera.get(6));
		System.out.println("Frame Count: " + camera.get(7));
		System.out.println("Mat Format: " + camera.get(8));
		System.out.println("Mode: " + camera.get(9));
		System.out.println("Bright: " + camera.get(10));
		System.out.println("Contrasto: " + camera.get(11));
		System.out.println("Saturazioen: " + camera.get(12));
		System.out.println("Hue: " + camera.get(13));
		System.out.println("Gain: " + camera.get(14));
		System.out.println("Exposure: " + camera.get(15));
		System.out.println("Convert_RGB: " + camera.get(16));

	}

	public ImageDeted run(ImageDeted id) {

		this.frame = new Mat();

		if (!id.status()) {
			if (id.getSemaforo() == 0)
				if (camera.grab()) {
					camera.retrieve(frame);
					id.setImage(frame);
					frame = null;
					id.setSemaforo(semaforo);
					return id;
				}
			return id;
		}

		camera.release();
		System.exit(0);

		return null;
	}
}